;*****************************************************
; 	Copyright (C) SEIKO EPSON CORP. 1997-2001
;	All rights Reserved
;
;	File name : strncmp.s
;	Function  :
;	       This is strncmp function
;	Revision  :
;		1997/03/25	V.Chan start
;		2001/12/06	T.Tazaki for GNU33(Linux)
;*****************************************************

;*****************************************************
; strncmp
;	compare N bytes of src1 and src2 (may be 0 terminated)
;	result > 0	if src1 > src2
;	result < 0	if src1 < src2
;	result = 0	if src1 = src2
;
; arguments : %r6:src1 addr, %r7:src2 addr, %r8:byte number
; return    : %r4:result
;*****************************************************

	.section .text
	.align 1
	.global strncmp
	.type	strncmp,@function

strncmp:
	ld.w	%r11, 1

strncmp_loop:
	cmp		%r8, 0
	jreq.d	strncmp_ret
	ld.w	%r10, 0			; return 0

	cmp		%r11, 0			; exit if both bytes = 0
	jreq	strncmp_ret
	ld.ub	%r10, [%r6]+	; load byte
	ld.ub	%r11, [%r7]+	; load byte
	sub		%r10, %r11
	jreq.d	strncmp_loop
	sub		%r8, 1

strncmp_ret:
	ret.d
	ld.w	%r4, %r10

